using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;

public partial class EditProfileMember : System.Web.UI.Page
{
    protected long Id
    {
        get
        {
            object o = ViewState["Id"];
            if (o != null)
                return (long)o;
            return long.MinValue;
        }
        set
        {
            ViewState["Id"] = value;
        }
    }
    ADESSA.Entities.Member _Member = new ADESSA.Entities.Member();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        LoadCurent();
        LoadData();
    }
    #region LoadCurent
    private void LoadCurent()
    {
        ContentPlaceHolder c = Page.Master.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
        UserControl usc = c.FindControl("MainMenu1") as UserControl;
        HtmlAnchor ahrEditMember = (HtmlAnchor)usc.FindControl("ahrEditMember");
        ahrEditMember.Attributes.Add("class", "selected1");
    }

    #endregion
    #region LoadData
    private void LoadData()
    {

        if (Session["MemberId"] != null)
        {
            this.Id = long.Parse(Session["MemberId"].ToString());
            if (this.Id != long.MinValue && this.Id != 0)
            {
                _Member = MemberService.GetMember(this.Id);
                if (_Member != null)
                {

                    txtFullName.Value = _Member.FullName;
                    txtTel.Value = _Member.Phone;
                    ltrEmail.Text = _Member.Email;
                    txtFax.Value = _Member.Fax;
                    txtAddress.Value = _Member.Address;
                    if (_Member.Sex == FetConstant.Mr)
                        rdoMale.Checked = true;
                    else if (_Member.Sex == FetConstant.Ms)
                        rdiFemale.Checked = true;
                    else if (_Member.Sex == FetConstant.MrMs)
                        rdoML.Checked = true;




                }
            }
        }
        else
            Response.Redirect("MemberLogin.aspx");
    }
    #endregion
    #region Update
    protected void linkNext_Click(object sender, EventArgs e)
    {

        if (this.Id != long.MinValue && this.Id != 0)
        {
            _Member = MemberService.GetMember(this.Id);
            _Member.FullName = txtFullName.Value.Trim();
            _Member.Phone = txtTel.Value.Trim();
            if (rdoMale.Checked)
                _Member.Sex = FetConstant.Mr;
            else if (rdiFemale.Checked)
                _Member.Sex = FetConstant.Ms;
            else
                _Member.Sex = FetConstant.MrMs;
            _Member.Fax = txtFax.Value.Trim();
            _Member.Address = txtAddress.Value.Trim();
            MemberService.UpdateMember(_Member);
            Response.Redirect(string.Format("Announcement.aspx?memId={0}", _Member.MemberID.ToString()));



        }
    }

    #endregion
    #region LogOut
    protected void linkLogout_Click(object sender, EventArgs e)
    {
        Session["MemberName"] = null;
        Session["MemberId"] = null;
        Response.Redirect("Default.aspx");
    }
    #endregion
}
